<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="迎着朝阳的博客" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    内网穿透工具ngrok和inlets，轻松将本地服务暴露到公网 |  迎着朝阳
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="https://dxysun.com/static/yan.png" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  
<script>
var _hmt = _hmt || [];
(function() {
	var hm = document.createElement("script");
	hm.src = "https://hm.baidu.com/hm.js?aa994a8d65700b8835787dd39d079d7e";
	var s = document.getElementsByTagName("script")[0]; 
	s.parentNode.insertBefore(hm, s);
})();
</script>


</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-nginxForInlets"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  内网穿透工具ngrok和inlets，轻松将本地服务暴露到公网
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2021/01/31/nginxForInlets/" class="article-date">
  <time datetime="2021-01-31T03:24:29.000Z" itemprop="datePublished">2021-01-31</time>
</a>   
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">2k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">7 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <p>介绍一下内网穿透工具ngrok 和 inlets，将本地服务暴露到公网</p>
<a id="more"></a>

<h1 id="介绍"><a href="#介绍" class="headerlink" title="介绍"></a>介绍</h1><p>通过使用内网穿透，将内部、或是开发中的服务通过「出口节点」暴露到公网，方便本地WEB外网访问、本地开发微信、TCP端口转发等。</p>
<h1 id="本地启动web服务"><a href="#本地启动web服务" class="headerlink" title="本地启动web服务"></a>本地启动web服务</h1><p>先在本地启动一个web服务，我用Flask在本地5000端口启动了一个web服务，本地访问如下，Flask启动web服务可参考<a href="https://dxysun.com/2021/01/31/pythonForFlask/">Flask使用教程</a></p>
<p><img src="https://tu.dxysun.com/20210131114437-20210131114438.png" alt=""></p>
<p><img src="https://tu.dxysun.com/20210131114507-20210131114508.png" alt=""></p>
<p>下面分别介绍一下如何使用ngrok和inlets在公网暴露本地web服务</p>
<h1 id="ngrok"><a href="#ngrok" class="headerlink" title="ngrok"></a>ngrok</h1><p><a href="https://ngrok.com/" target="_blank" rel="noopener">ngrok国外服务</a></p>
<p><a href="http://www.ngrok.cc/" target="_blank" rel="noopener">Sunny-Ngrok国内服务</a></p>
<h2 id="使用国外的ngrok服务"><a href="#使用国外的ngrok服务" class="headerlink" title="使用国外的ngrok服务"></a>使用国外的ngrok服务</h2><h3 id="1、下载ngrok安装包"><a href="#1、下载ngrok安装包" class="headerlink" title="1、下载ngrok安装包"></a>1、下载ngrok安装包</h3><p>解压</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">unzip &#x2F;path&#x2F;to&#x2F;ngrok.zip</span><br></pre></td></tr></table></figure>

<h3 id="2、在国外的ngrok官网注册账户"><a href="#2、在国外的ngrok官网注册账户" class="headerlink" title="2、在国外的ngrok官网注册账户"></a>2、在国外的ngrok官网注册账户</h3><p>ngrok启动时设置账户的token，运行命令如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;ngrok authtoken token</span><br></pre></td></tr></table></figure>

<p>token为ngrok官网账户的token，在个人页面获取，如下</p>
<p><img src="https://tu.dxysun.com/20210131122027-20210131122029.png" alt=""></p>
<h3 id="3、开启本地端口转发"><a href="#3、开启本地端口转发" class="headerlink" title="3、开启本地端口转发"></a>3、开启本地端口转发</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;ngrok http 5000</span><br></pre></td></tr></table></figure>

<p>转发本地5000端口，运行成功如下图所示</p>
<p><img src="https://tu.dxysun.com/20210131114051-20210131114051.png" alt=""></p>
<p>访问<a href="https://626888298b58.ngrok.io" target="_blank" rel="noopener">https://626888298b58.ngrok.io</a> ，即可访问到本地服务，访问如下</p>
<p><img src="https://tu.dxysun.com/20210131114706-20210131114706.png" alt=""></p>
<p><img src="https://tu.dxysun.com/20210131114741-20210131114742.png" alt=""></p>
<p>ngrok提供了http和https两种访问方式，不过每次重启，ngrok提供的域名前缀都会变的，想固定域名前缀的话就要收费了。</p>
<p>浏览器访问 <a href="http://127.0.0.1:4040/" target="_blank" rel="noopener">http://127.0.0.1:4040/</a> ，可进入管理页面，查看本地服务访问情况。</p>
<p><img src="https://tu.dxysun.com/20210131120756-20210131120757.png" alt=""></p>
<p>ngrok我记得之前官网还提供了服务端配置教程，现在官网好像没了这个教程，而且客户端升级后也不支持了，可能官方不想让我们自己搭建ngrok服务了。</p>
<p>更多教程<a href="https://dashboard.ngrok.com/get-started/setup" target="_blank" rel="noopener">参考官网</a></p>
<h2 id="使用国内的ngrok服务"><a href="#使用国内的ngrok服务" class="headerlink" title="使用国内的ngrok服务"></a>使用国内的ngrok服务</h2><h3 id="1、首先在Sunny-Ngrok注册账户"><a href="#1、首先在Sunny-Ngrok注册账户" class="headerlink" title="1、首先在Sunny-Ngrok注册账户"></a>1、首先在<a href="http://www.ngrok.cc/" target="_blank" rel="noopener">Sunny-Ngrok</a>注册账户</h3><p>登录，进入管理界面，开通隧道，不想付费的话有免费的服务器可用</p>
<p><img src="https://tu.dxysun.com/20210131115331-20210131115333.png" alt=""></p>
<h3 id="2、开通隧道后获取隧道id"><a href="#2、开通隧道后获取隧道id" class="headerlink" title="2、开通隧道后获取隧道id"></a>2、开通隧道后获取隧道id</h3><p><img src="https://tu.dxysun.com/20210131115605-20210131115606.png" alt=""></p>
<p>获取隧道id，本地映射的是5000端口，可获得一个免费域名进行访问，该域名是固定的，不像国外的ngrok服务，每次启动都会变。</p>
<h3 id="3、下载Ngrok客户端"><a href="#3、下载Ngrok客户端" class="headerlink" title="3、下载Ngrok客户端"></a>3、下载Ngrok客户端</h3><p>运行ngrok服务</p>
<p><a href="https://www.ngrok.cc/download.html" target="_blank" rel="noopener">下载地址</a>，使用下面的命令启动ngrok，使用上一步获取隧道id</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.&#x2F;sunny clientid 隧道id</span><br></pre></td></tr></table></figure>

<p>启动成功如下图所示</p>
<p><img src="https://tu.dxysun.com/20210131120204-20210131120204.png" alt=""></p>
<p>访问 <a href="http://dxysun.free.idcfengye.com/" target="_blank" rel="noopener">http://dxysun.free.idcfengye.com/</a>  ，即可访问到本地服务，访问如下</p>
<p><img src="https://tu.dxysun.com/20210131120329-20210131120330.png" alt=""></p>
<p><img src="https://tu.dxysun.com/20210131120404-20210131120405.png" alt=""></p>
<p> Sunny-Ngrok 不提供https的访问，想要https的访问就要付费了，免费的服务器访问速度比较慢，想要提高访问速度也需要付费。</p>
<p>浏览器访问 <a href="http://127.0.0.1:4040/" target="_blank" rel="noopener">http://127.0.0.1:4040/</a> ，可进入管理页面，查看本地服务访问情况。</p>
<p><img src="https://tu.dxysun.com/20210131120956-20210131120957.png" alt=""></p>
<p>更多教程<a href="http://www.ngrok.cc/_book/start/ngrok_linux.html" target="_blank" rel="noopener">参考官网</a></p>
<h1 id="inlets"><a href="#inlets" class="headerlink" title="inlets"></a>inlets</h1><p>inlets 利用反向代理和 Websocket 隧道，将内部、或是开发中的服务通过「出口节点」暴露到公网。出口节点可以是几块钱一个月的 VPS，也可以是任何带有公网 IPv4 的电脑。 </p>
<p><a href="https://github.com/inlets/inlets" target="_blank" rel="noopener">github地址</a></p>
<p>inlets服务是需要自己搭建的，不想自己搭建使用官方服务是要付费的。</p>
<h2 id="安装使用"><a href="#安装使用" class="headerlink" title="安装使用"></a>安装使用</h2><h3 id="1、安装inlets"><a href="#1、安装inlets" class="headerlink" title="1、安装inlets"></a>1、安装inlets</h3><h4 id="服务端自动安装"><a href="#服务端自动安装" class="headerlink" title="服务端自动安装"></a>服务端自动安装</h4><p>首先要有一台服务器，最好可以域名访问。</p>
<p>服务端自动安装</p>
<p>可使用 <code>curl</code> 和辅助脚本：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"># 安装到当前目录</span><br><span class="line">curl -sLS https:&#x2F;&#x2F;get.inlets.dev | sh</span><br><span class="line"></span><br><span class="line"># 安装到 &#x2F;usr&#x2F;local&#x2F;bin&#x2F;</span><br><span class="line">curl -sLS https:&#x2F;&#x2F;get.inlets.dev | sudo sh</span><br></pre></td></tr></table></figure>

<p>使用以上命令安装时可能会报如下错误</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">[root@dxy conf.d]# curl -sLS https:&#x2F;&#x2F;get.inlets.dev | sudo sh</span><br><span class="line">curl: (7) Failed connect to raw.githubusercontent.com:443; 拒绝连接</span><br></pre></td></tr></table></figure>

<p>由于某些<code>你懂的原因</code>，导致GitHub的<code>raw.githubusercontent.com</code>域名解析被污染了。</p>
<p>查询真实IP<br>在 <a href="https://www.ipaddress.com/" target="_blank" rel="noopener">https://www.ipaddress.com/</a>  查询raw.githubusercontent.com的真实IP。</p>
<p>通过修改<code>/etc/hosts</code>解决此问题</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">199.232.28.133 raw.githubusercontent.com</span><br></pre></td></tr></table></figure>

<p>修改完成后再执行一次自动安装命令</p>
<p>使用以上办法如果安装还有问题的，则可以自己手动安装</p>
<h4 id="服务端手动安装"><a href="#服务端手动安装" class="headerlink" title="服务端手动安装"></a>服务端手动安装</h4><p>使用如下命令下载inlets</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -sSLf https:&#x2F;&#x2F;github.com.cnpmjs.org&#x2F;inlets&#x2F;inlets&#x2F;releases&#x2F;download&#x2F;2.7.12&#x2F;inlets  --output .&#x2F;inlets</span><br></pre></td></tr></table></figure>

<blockquote>
<p><a href="https://github.com.cnpmjs.org" target="_blank" rel="noopener">https://github.com.cnpmjs.org</a>  ，是github的加速地址，国内访问速度还是可以的，比raw.githubusercontent.com要快</p>
</blockquote>
<p>然后加执行权限，移到bin目录下，方便其他用户直接使用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">chmod +x inlets </span><br><span class="line">mv inlets &#x2F;usr&#x2F;local&#x2F;bin</span><br></pre></td></tr></table></figure>

<blockquote>
<p>以上均在root用户下执行，如不是root用户，需要用sudo命令执行</p>
</blockquote>
<h4 id="客户端安装"><a href="#客户端安装" class="headerlink" title="客户端安装"></a>客户端安装</h4><p>如果是Mac，则可以使用 <code>brew</code>：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">brew install inlets</span><br></pre></td></tr></table></figure>

<blockquote>
<p>其他客户端可直接下载安装，<a href="https://github.com.cnpmjs.org/inlets/inlets/releases" target="_blank" rel="noopener">下载地址</a></p>
</blockquote>
<h3 id="2、运行inlets"><a href="#2、运行inlets" class="headerlink" title="2、运行inlets"></a>2、运行inlets</h3><p>首先在服务端运行inlets，运行端口为8090</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">inlets server --port&#x3D;8090 --token&#x3D;dxysun</span><br></pre></td></tr></table></figure>

<blockquote>
<p>token可以自定义，客户端运行需要设置这个token</p>
<p>上面的命令只能在前台运行，若想在后台运行，可使用如下命令</p>
<p><code>nohup inlets server --port=8090 --token=dxysun &gt; nohup.log 2&gt;&amp;1 &amp;</code></p>
</blockquote>
<p>运行结果</p>
<p><img src="https://tu.dxysun.com/20210131142351-20210131142352.png" alt=""></p>
<p>然后在客户端运行</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">inlets client  --remote&#x3D;vps.dxysun.com:8090  --upstream&#x3D;http:&#x2F;&#x2F;127.0.0.1:5000  --token&#x3D;dxysun</span><br></pre></td></tr></table></figure>

<blockquote>
<p>remote 参数是远程服务器的地址，我的服务器的域名是 vps.dxysun.com</p>
<p>upstream 参数是本地服务的地址</p>
<p>token是服务端设置的token</p>
<p>上面的命令只能在前台运行，若想在后台运行，可使用如下命令</p>
<p><code>nohup inlets client --remote=vps.dxysun.com:8090 --upstream=http://127.0.0.1:5000 --token=dxysun &gt; nohup.log 2&gt;&amp;1 &amp;</code></p>
</blockquote>
<p>运行结果</p>
<p><img src="https://tu.dxysun.com/20210131142428-20210131142428.png" alt=""></p>
<h3 id="3、访问服务"><a href="#3、访问服务" class="headerlink" title="3、访问服务"></a>3、访问服务</h3><p>服务访问地址为 <a href="http://vps.dxysun.com:8090/" target="_blank" rel="noopener">http://vps.dxysun.com:8090/</a>  ，访问情况如下</p>
<p><img src="https://tu.dxysun.com/20210131142239-20210131142240.png" alt=""></p>
<p><img src="https://tu.dxysun.com/20210131142306-20210131142306.png" alt=""></p>
<h2 id="https访问设置"><a href="#https访问设置" class="headerlink" title="https访问设置"></a>https访问设置</h2><p>由于inlets并不直接提供https服务，<a href="https://inlets.dev/" target="_blank" rel="noopener">inlets pro</a> 提供https服务，不过需要付费。</p>
<p>但是如果自己拥有域名和服务器，想要使用https，可配合nginx配置https访问。</p>
<p>配置教程如下</p>
<p>首先要对要使用的域名申请ssl证书，阿里云、腾讯云、网易云都可申请免费的ssl证书，我这边之前配置过https的域名是<code>love.dxysun.com</code> ，就拿这个域名来示例一下。</p>
<p>https的nginx配置可自行百度，下面只介绍inlets相关的nginx配置。</p>
<p>先启动服务端的inlets服务，这里服务端运行端口为 8090</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">inlets server --port&#x3D;8090 --token&#x3D;dxysun</span><br></pre></td></tr></table></figure>

<p>然后配置nginx</p>
<p>服务端nginx的配置文件如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">#http访问配置</span><br><span class="line">location &#x2F; &#123;</span><br><span class="line">            proxy_pass http:&#x2F;&#x2F;127.0.0.1:8090;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"># ws通道访问配置</span><br><span class="line">location &#x2F;tunnel &#123;</span><br><span class="line">            proxy_pass http:&#x2F;&#x2F;127.0.0.1:8090;</span><br><span class="line">            proxy_http_version 1.1;</span><br><span class="line">            proxy_set_header Upgrade $http_upgrade;</span><br><span class="line">            proxy_set_header Connection &quot;upgrade&quot;;</span><br><span class="line">            proxy_read_timeout 86400;</span><br><span class="line">            proxy_set_header X-real-ip $remote_addr;</span><br><span class="line">            proxy_set_header X-Forwarded-For $remote_addr;</span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>

<p>nginx配置完成后使用<code>nginx -s reload</code> 重新加载配置</p>
<p>客户端启动</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">inlets client  --remote&#x3D;love.dxysun.com  --upstream&#x3D;http:&#x2F;&#x2F;127.0.0.1:5000  --token&#x3D;dxysun</span><br></pre></td></tr></table></figure>

<p>配置成功，运行结果如下</p>
<p><img src="https://tu.dxysun.com/20210131144537-20210131144537.png" alt=""></p>
<p>访问情况</p>
<p><img src="https://tu.dxysun.com/20210131144655-20210131144656.png" alt=""></p>
<p><img src="https://tu.dxysun.com/image-20210131144719540-20210131153028.png" alt=""></p>
<p>至此，inlets的https配置访问成功。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>对这三种内网穿透工具做下对比</p>
<table>
<thead>
<tr>
<th>工具</th>
<th>配置</th>
<th>https</th>
<th>访问速度</th>
<th>管理页面</th>
<th>固定域名</th>
</tr>
</thead>
<tbody><tr>
<td>ngrok</td>
<td>简单</td>
<td>支持</td>
<td>国外的，慢，提速需付费</td>
<td>支持</td>
<td>不支持，固定域名需付费</td>
</tr>
<tr>
<td>Sunny-Ngrok</td>
<td>简单</td>
<td>支持，需付费</td>
<td>国内的，速度一般，提速需付费</td>
<td>支持</td>
<td>支持，免费的</td>
</tr>
<tr>
<td>inlets</td>
<td>稍微复杂点</td>
<td>支持，需自行配置，也可使用官方的，需付费</td>
<td>自己的服务器，视服务器带宽而定</td>
<td>不支持</td>
<td>支持，使用自己的域名，也可使用官方的，需付费</td>
</tr>
</tbody></table>
<p>总的来说，三个工具各有优缺点，若只是简单使用下，推荐使用Sunny-Ngrok，配置简单，还有免费自定义域名；如果有自己的服务器和域名，并且不嫌配置麻烦的话(其实也不麻烦)，推荐使用inlets，灵活度高；至于ngrok，由于是国外的服务，速度你懂的，而且不支持固定域名，就不推荐了。</p>
<h1 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h1><p><a href="https://github.com/inlets/inlets" target="_blank" rel="noopener">inlets</a></p>
<p><a href="https://inlets.dev/" target="_blank" rel="noopener">inlets.dev</a></p>
<p><a href="https://ngrok.com/" target="_blank" rel="noopener">ngrok国外服务</a></p>
<p><a href="http://www.ngrok.cc/" target="_blank" rel="noopener">Sunny-Ngrok国内服务</a></p>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://dxysun.com/2021/01/31/nginxForInlets/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/nginx/" rel="tag">nginx</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2021/03/27/designPatternForDesignPrinciple/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            软件设计原则
          
        </div>
      </a>
    
    
      <a href="/2021/01/31/pythonForFlask/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">python Flask使用教程</div>
      </a>
    
  </nav>

  
   
  
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2024
        <i class="ri-heart-fill heart_icon"></i> dxysun
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
        <li>
          <a href="https://beian.miit.gov.cn" target="_black" rel="nofollow">豫ICP备17012675号-1</a>
        </li>
        
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="https://dxysun.com/static/logo.png" alt="迎着朝阳"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/photos">相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://tu.dxysun.com/alipay-20201219151322.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://tu.dxysun.com/weixin-20201219151346.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


<script src="/js/dz.js"></script>



    
  </div>
</body>

</html>